package com.wing.ext.service;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.wing.common.util.GUID;
import com.wing.common.util.PageBean;
import com.wing.ext.dao.Site_userDao;
import com.wing.ext.domain.Site_user;
/**
 * 
 * @author please write yout name
 * 
 */
@Service
@Transactional
public class Site_userManager {
	@Autowired
	private Site_userDao site_userdao;
	
	
	/**
	 * 获得该对象所有数据的列表
	 * 
	 * @return list
	 */
	public List<Map<String,Object>> findAll(){
		return site_userdao.findAll();	 
	}
	
	public PageBean findPageList(int currentPage, int pageSize,String siteId){
		return site_userdao.findPageList(currentPage,pageSize,siteId);	 
	}
	
	/**
	 * 通过id得到对象
	 *
	 * @param  id
	 * @return pObject
	 */
	public Site_user findById(String id){
		return site_userdao.findById(id);	 
	}
	
	/**
	 * 保存对象
	 *
	 * @param  site_user
	 */
	public void saveSite_user(Site_user site_user){
		if(site_user.getId() == null ||  "".equals(site_user.getId())){
			site_user.setId(new GUID().toString());
			site_userdao.insert(site_user);
		}else{
			site_userdao.update(site_user);
		}
	}

	public List findUsersByLoginName(String lgname) {
		return site_userdao.findUsersByLoginName(lgname);
	}

	/**
	 * 编辑对象
	 *
	 * @param  site_user
	 */
	public void updateSite_user(Site_user site_user){
		site_userdao.update(site_user);
	}
	
	 /**
	 * 删除对象
	 *
	 * @param  chk 对象id数组
	 */
	public void deleteSite_users(String[] chk) {
		for(int i=0;i<chk.length;i++){
			site_userdao.delete(chk[i]);
		}
	}

	public Map findSiteUser(String site_id, String login_name, String password) {
		List<Map<String, Object>> list = site_userdao.findSiteUser(site_id,login_name,password);
		if(list.size()>0){
			return (Map)list.get(0);
		}
		return null;
	}
}



